# 2025.03.12 更新 - 支持Linux/Windows/macOS的通用配置
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(ConcurrentAllocator
    VERSION 1.0.1
    LANGUAGES CXX
    DESCRIPTION "High-performance concurrent memory allocator with thread caching"
)

# 显式声明源文件（避免GLOB潜在问题）[3,9](@ref)
set(SRC_FILES
    Benchmark.cpp
    CentralCache.cpp
    Common.cpp
    ObjectPool.cpp 
    PageCache.cpp
    ThreadCache.cpp
    UnitTest.cpp
)

# 生成可执行目标[1,10](@ref)
add_executable(concurrent_alloc ${SRC_FILES})

# 包含头文件目录（现代CMake推荐方式）[5,7](@ref)
target_include_directories(concurrent_alloc PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}  # 包含所有本地头文件
)

# 设置C++17标准特性[3,10](@ref)
set_target_properties(concurrent_alloc PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
    CXX_EXTENSIONS OFF
)

# 线程库支持（跨平台自动配置）[1,7](@ref)
if(UNIX)
    target_compile_options(concurrent_alloc PRIVATE -pthread)
    target_link_libraries(concurrent_alloc PRIVATE pthread)
endif()



# 安装配置（支持make install）[4,6](@ref)
install(TARGETS concurrent_alloc
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# 调试信息输出[6,9](@ref)
message(STATUS "Project Version: ${PROJECT_VERSION}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Install Prefix: ${CMAKE_INSTALL_PREFIX}")